package cn.sibu.disalllowtouchintercept;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;


public class ComfigDialog implements OnClickListener {
    private Context context;
    private Window window;
    private Dialog dialog;
    private OnItemClickListener onItemClickListener;

    @Override
    public void onClick(View v) {
        if (onItemClickListener != null) {
            switch (v.getId()) {
                /**
                 * 相册的选项
                 */
                case R.id.take_photo:
                    onItemClickListener.onItemClick(v, 0);
                    break;
                case R.id.select_from_album:
                    onItemClickListener.onItemClick(v, 1);
                    break;
                case R.id.cancel_take_pic:
                    onItemClickListener.onItemClick(v, 2);
                    break;
            }
        }
    }

    public interface OnItemClickListener {//弹出相册对话框与分享二维码共用的的回调接口

        void onItemClick(View v, int position);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public ComfigDialog(Context context) {
        this.context = context;
    }


    public void myDialog(String title1,String title2) {

        View view = LayoutInflater.from(context).inflate(R.layout.photo_dialog_layout, null);
        dialog = new Dialog(context, R.style.dialog_show_style);
        dialog.setContentView(view);
        dialog.setCancelable(true);// 返回键处理
        dialog.show();
        window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.my_style);// 效果
        Button takePhoto = (Button) view.findViewById(R.id.take_photo);
        Button select = (Button) view.findViewById(R.id.select_from_album);
        Button cancle = (Button) view.findViewById(R.id.cancel_take_pic);
        takePhoto.setText(title1);
        select.setText(title2);
        takePhoto.setOnClickListener(this);
        select.setOnClickListener(this);
        cancle.setOnClickListener(this);

    }


    /**
     *
     * @param
     * @return void
     * @throw
     */
    public void dismiss() {
        dialog.dismiss();
    }


}
